<template>
  <j-modal :title="title" :width="width" :visible="visible" :confirmLoading="confirmLoading" :maskClosable="false"
    :keyboard="false" :forceRender="true" v-bind:prefixNo="prefixNo" switchHelp switchFullscreen @cancel="handleCancel"
    wrapClassName="ant-modal-cust-warp" :id="prefixNo" style="top:5%;height: 100%;overflow-y: hidden">
    <template slot="footer">
      <a-button @click="handleCancel">{{ $t('inPrint.cancel') }}</a-button>
      <!-- <a-button v-if="isCanCheck" @click="handleOkAndCheck">{{$t('popup.saveReview')}}</a-button> -->
      <a-button type="primary" @click="handleOk" :disabled="submitBtnDisabled">{{ $t('commodityManagement.preservation') }}</a-button>
    </template>
    <div style="position:absolute;bottom:53px;right:0;z-index:11" v-if="showRecover && !model.id">
      <span>{{ $t('popup.recoveryPrompt') }}</span>
      <a-button type="link" @click="recover" :disabled="submitBtnDisabled">{{$t('popup.recover')}}</a-button>
      <a-button type="link" @click="lose" :disabled="submitBtnDisabled">{{$t('popup.lose')}}</a-button>
    </div>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('manuManagement.supplier')"
              data-step="1" :data-title="$t('manuManagement.supplier')"
              :data-intro="$t('popup.supplierMustBeSelectedIt')">
              <a-select :placeholder="$t('manuManagement.selectSupplier')"
                v-decorator="['organId', validatorRules.organId]" :disabled="!rowCanEdit"
                :dropdownMatchSelectWidth="false" showSearch optionFilterProp="children">
                <div slot="dropdownRender" slot-scope="menu">
                  <v-nodes :vnodes="menu" />
                  <a-divider style="margin: 4px 0;" />
                  <div v-if="isTenant" style="padding: 4px 8px; cursor: pointer;" @mousedown="e => e.preventDefault()"
                    @click="addSupplier"><a-icon type="plus" /> {{ $t('popup.newSupplier') }}</div>
                </div>
                <a-select-option v-for="(item, index) in supList" :key="index" :value="item.id">
                  {{ item.supplier }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          
          <!-- 搜索 -->
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('popup.relatedOrder')" data-step="3"
              :data-title="$t('popup.relatedOrder')" :data-intro="$t('popup.purchaseReceiptAfterOrder')">
              <a-input-search :placeholder="$t('popup.pleaseSelectAssociated')" v-decorator="['linkNumber',validatorRules.linkNumber]"
                @search="onSearchLinkNumber" :readOnly="true" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('setailManagement.documentDate')">
              <j-date v-decorator="['operTime', validatorRules.operTime]" :show-time="true" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('setailManagement.documentNo')"
              data-step="2" :data-title="$t('setailManagement.documentNo')"
              :data-intro="$t('popup.theNumberIsGenerated')">
              <a-input :placeholder="$t('setailManagement.pleaseEnterTheDocumentNumber')" v-decorator.trim="[ 'number',validatorRules.number  ]" :readOnly="true"/>

            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('defaultTranslate.operator')"
              data-step="3" :data-title="$t('defaultTranslate.operator')">
              <a-input :placeholder="$t('defaultTranslate.operator')" v-decorator.trim="['userName']"
                :readOnly="true" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" v-show="false">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator.trim="['creator']" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('otherJS.arrivalDate')">
              <j-date v-decorator="['arrivalTime']" :show-time="true"
                :placeholder="$t('otherJS.pleaseSelectTheArrDate')" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('otherJS.deliveryMethod')">
              <a-input :placeholder="$t('otherJS.pleaseEnterDeliveryMethod')" v-decorator.trim="['deliveryMethod']" />
            </a-form-item>
          </a-col>
        </a-row>
        
        <a-col :lg="6" :md="12" :sm="24" v-show="false">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol"
              :label="$t('purchasingManagement.WarehousingWarehouse')">
              <a-input :placeholder="$t('purchasingManagement.pleaseEnterDutyParagraph')" v-decorator="['custom5']"
                :readOnly="true" />
            </a-form-item>
          </a-col>
        <a-col :lg="6" :md="12" :sm="24" v-show="false">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol"
              :label="$t('purchasingManagement.WarehousingWarehouse')">
              <a-input :placeholder="$t('purchasingManagement.pleaseEnterDutyParagraph')" v-decorator="['depotId']"
                :readOnly="true" />
            </a-form-item>
          </a-col>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="24" :md="24" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }" >
              <span>{{$t('popup.documentRemark')}}：</span>
              <a-textarea :rows="1" :placeholder="$t('reportQuery.pleaseEnterComments')" v-decorator="['remark']"
                style="margin-top:8px;width: 88%;" />
            </a-form-item>
          </a-col>
        </a-row>
        <j-editable-table id="billModal" :ref="refKeys[0]" :loading="materialTable.loading"
          :columns="materialTable.columns" :dataSource="materialTable.dataSource" :minWidth="minWidth" :maxHeight="300"
          :disabledRows="{id:disabledRowIds}"
          :rowNumber="false" :rowSelection="rowCanEdit" :actionButton="rowCanEdit" :dragSort="false"
          @valueChange="barCodeValueChange" @inputPurchaseValueChange="onValueChange" @added="onAdded"
          @deleted="onDeleted">
          <template #buttonAfter>
            <a-row v-if="rowCanEdit" :gutter="24" style="float:left;padding-bottom: 5px;" data-step="4"
              :data-title="$t('popup.codeScanningEntry')" :data-intro="$t('popup.thisSupportsGun')">
              <a-col v-if="scanStatus" :md="6" :sm="24">
                <a-button @click="scanEnter">{{ $t('popup.codeScanningEntry') }}</a-button>
              </a-col>
              <a-col v-if="!scanStatus" :md="16" :sm="24" style="padding: 0 6px 0 12px">
                <a-input :placeholder="$t('popup.pleaseScanBarcode')" v-model="scanBarCode" @pressEnter="scanPressEnter"
                  ref="scanBarCode" />
              </a-col>
              <a-col v-if="!scanStatus" :md="6" :sm="24" style="padding: 0px">
                <a-button @click="stopScan">{{ $t('popup.stowScanningCode') }}</a-button>
              </a-col>
            </a-row>
            <a-row :gutter="24" style="float:left;padding-bottom: 5px;">
              <a-col :md="24" :sm="24">
                <a-button style="margin-left: 8px" @click="handleHistoryBillList"><a-icon type="history" />{{
                    $t('popup.historicalDocuments')
                }}</a-button>
              </a-col>
            </a-row>
          </template>
          <template #rowIndex="record">
            <div style="text-align: center;">{{ record.index + 1 }}</div>
          </template>
          <template #delete="record">
            <div style="text-align: center;">
              <a-popconfirm :title="$t('manuManagement.areDelete')"
                @confirm="() => removeRows(record)">
                <a-icon type="delete"></a-icon>
              </a-popconfirm>
            </div>
          </template>
        </j-editable-table>
        <a-row class="form-row" :gutter="24">
          <!-- <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('inPrint.preferentialRate')" data-step="5" :data-title="$t('inPrint.preferentialRate')"
                         :data-intro="$t('popup.proportionDiscount')">
              <a-input style="width:185px;" :placeholder="$t('popup.pleaseDiscountRate')" v-decorator.trim="[ 'discount' ]" suffix="%" @keyup="onKeyUpDiscount"/>
            </a-form-item>
          </a-col> -->
          <a-col :lg="6" :md="12" :sm="24" v-show="false">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('inPrint.paymentPreference')"
              data-step="6" :data-title="$t('inPrint.paymentPreference')" :data-intro="$t('popup.theAmountGoods')">
              <a-input :placeholder="$t('popup.pleasePaymentPreference')" v-decorator.trim="['discountMoney']"
                @keyup="onKeyUpDiscountMoney" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" v-show="false">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('inPrint.amountAfter')" data-step="7"
              :data-title="$t('inPrint.amountAfter')" :data-intro="$t('popup.amountAmountGoodsIn')">
              <a-input :placeholder="$t('popup.pleaseEnterAfterDiscount')" v-decorator.trim="['discountLastMoney']"
                :readOnly="true" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24"></a-col>
        </a-row>
        <a-row class="form-row" :gutter="24" v-show="false">
          <!-- <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('setailManagement.settlementAccount')"
              data-step="9" :data-title="$t('setailManagement.settlementAccount')"
              :data-intro="$t('popup.ifMultipleAreBox')">
              <a-select style="width:185px;" :placeholder="$t('popup.selectSettlementAccount')"
                v-decorator="['accountId']" :dropdownMatchSelectWidth="false" allowClear @select="selectAccount">
                <div slot="dropdownRender" slot-scope="menu">
                  <v-nodes :vnodes="menu" />
                  <a-divider style="margin: 4px 0;" />
                  <div v-if="isTenant" style="padding: 4px 8px; cursor: pointer;" @mousedown="e => e.preventDefault()"
                    @click="addAccount"><a-icon type="plus" /> {{ $t('popup.newAccount') }}</div>
                </div>
                <a-select-option v-for="(item, index) in accountList" :key="index" :value="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
              <a-tooltip :title="$t('popup.multiAccountDetails')">
                <a-button type="default" icon="folder" style="margin-left: 8px;" size="small"
                  v-show="manyAccountBtnStatus" @click="handleManyAccount" />
              </a-tooltip>
            </a-form-item>
          </a-col> -->
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('manuManagement.payDeposit')">
              <a-input :placeholder="$t('popup.pleaseEnterPaymentDeposit')"
                v-decorator.trim="['changeAmount', validatorRules.price]" @keyup="onKeyUpChangeAmount" />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
          </a-col>
          <a-col :lg="6" :md="12" :sm="24">
          </a-col>
        </a-row>
        <a-row class="form-row" :gutter="24">
          <a-col :lg="6" :md="12" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="$t('inPrint.enclosure')" data-step="10"
              :data-title="$t('inPrint.enclosure')" :data-intro="$t('popup.youUploadPictures')">
              <j-upload :fileList="fileList" bizPath="bill" :key="model.uploadKey || 1"></j-upload>

            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <many-account-modal ref="manyAccountModalForm" @ok="manyAccountModalFormOk"></many-account-modal>
    <vendor-modal ref="vendorModalForm" @ok="vendorModalFormOk"></vendor-modal>
    <account-modal ref="accountModalForm" @ok="accountModalFormOk"></account-modal>
    <link-bill-list ref="linkBillList" @ok="linkBillListOk"></link-bill-list>
    <history-bill-list ref="historyBillListModalForm"></history-bill-list>
  </j-modal>
</template>
<script>
import pick from 'lodash.pick'
import ManyAccountModal from '../dialog/ManyAccountModal'
import LinkBillList from '../dialog/LinkBillList'
import VendorModal from '../../system/modules/VendorModal'
import AccountModal from '../../system/modules/AccountModal'
import HistoryBillList from '../dialog/HistoryBillList'
import { FormTypes } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
import { BillModalMixin } from '../mixins/BillModalMixin'
import { getCurrentSystemConfig } from '@/api/api'
import { getMpListShort, changeListFmtMinus, handleIntroJs } from "@/utils/util"
import JUpload from '@/components/jeecg/JUpload'
import JDate from '@/components/jeecg/JDate'
import Vue from 'vue'
export default {
  name: "PurchaseOrderModal",
  provide(){
    return {
      getConfig: ()=>{
        return {organId : this.form.getFieldValue('organId')}
      }
    }
  },
  mixins: [JEditableTableMixin, BillModalMixin],
  components: {
    ManyAccountModal,
    LinkBillList,
    VendorModal,
    AccountModal,
    HistoryBillList,
    JUpload,
    JDate,
    VNodes: {
      functional: true,
      render: (h, ctx) => ctx.props.vnodes,
    }
  },
  data() {
    return {
      title: this.$t('setailManagement.operation'),
      width: '1600px',
      moreStatus: false,
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      visible: false,
      supList: [],
      depotList: [],
      operTimeStr: '',
      prefixNo: 'CJBJ',
      fileList: [],
      rowCanEdit: true,
      purchaseBySaleFlag: true,
      model: {},
      disabledRowIds:[],//禁用的行
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      refKeys: ['materialDataTable',],
      tableKeys: ['materialDataTable',],
      activeKey: 'materialDataTable',
      materialTable: {
        loading: false,
        dataSource: [],
        columns: [
          { title: this.$t('commodityManagement.delete'), width: '3%', key: 'delete', type: 'slot' },
          { title: this.$t('defaultTranslate.lineNumber'), key: 'rowIndex', width: '4%', type: 'slot' },
          { title: this.$t('setailManagement.warehouseName'), key: 'depotId', width: '7%', type: FormTypes.hidden },
          // {
          //   title: this.$t('reportQuery.barcode'), key: 'barCode', width: '8%', type: FormTypes.popupJsh, kind: 'material', multi: true,
          //   // validateRules: [{ required: true, message:'${title}'+this.$t('inPrint.cannotTe') }]
          // },
          { title: this.$t('otherJS.goodsId'), key: 'meId', width: '6%', type: FormTypes.hidden },
          { title: this.$t('otherJS.goodsId'), key: 'materialId', width: '6%', type: FormTypes.hidden },
          { title: this.$t('otherJS.productName'), width: '20%', key: 'name',type: FormTypes.popupJsh, kind: 'material', multi: true, placeholder: this.$t('otherJS.productName') },
          { title: this.$t('reportQuery.specification'), key: 'standard', width: '5%', type: FormTypes.normal },
          { title: this.$t('reportQuery.category'), key: 'categoryName', width: '6%', type: FormTypes.input,readonly:true  },
          { title: this.$t('reportQuery.model'), key: 'model', width: '5%', type: FormTypes.normal },
          { title: this.$t('reportQuery.color'), key: 'color', width: '5%', type: FormTypes.normal },
          { title: this.$t('reportQuery.extendedInformation'), key: 'materialOther', width: '5%', type: FormTypes.normal },
          { title: this.$t('reportQuery.inventory'), key: 'stock', width: '5%', type: FormTypes.normal },
          { title: this.$t('reportQuery.unit'), key: 'unit', width: '6%', type: FormTypes.normal },
          { title: this.$t('commodityManagement.multiAttribute'), key: 'sku', width: '4%', type: FormTypes.normal },
          { title: this.$t('popup.originalQuantity'), key: 'preNumber', width: '4%', type: FormTypes.normal },
          { title: this.$t('popup.purchased'), key: 'finishNumber', width: '4%', type: FormTypes.normal },
          {
            title: this.$t('reportQuery.quantity'), key: 'operNumber', width: '5%', type: FormTypes.inputNumber, statistics: true,
            validateRules: [{ required: true, message: '${title}' + this.$t('inPrint.cannotTe') }]
          },
          { title: this.$t('reportQuery.unitPrice'), key: 'unitPrice', width: '6%', type: FormTypes.inputNumber },
          { title: this.$t('reportQuery.taxMoney'), key: 'allPrice', width: '6%', type: FormTypes.inputNumber, statistics: true },
          { title: this.$t('basicInformation.taxRate'), key: 'taxRate', width: '5%', type: FormTypes.inputNumber, placeholder: '%' },
          { title: this.$t('inPrint.taxAmount'), key: 'taxMoney', width: '5%', type: FormTypes.inputNumber, readonly: true, statistics: true },
          { title: this.$t('inPrint.taxUnitPrice'), key: 'taxUnitPrice', width: '5%', type: FormTypes.inputNumber, readonly: true, statistics: true },
          { title: this.$t('inPrint.totalTax'), key: 'taxLastMoney', width: '6%', type: FormTypes.hidden, statistics: true },
          { title: this.$t('financialManagement.remarks'), key: 'remark', width: '5%', type: FormTypes.input },
          { title: this.$t('otherJS.promotionPrice'), key: 'priceNote', width: '6%', type: FormTypes.input },
          { title: this.$t('popup.associationID'), key: 'linkId', width: '5%', type: FormTypes.hidden },
          { title: this.$t('popup.associationID'), key: 'custom5', width: '5%', type: FormTypes.hidden },
          
          // 过滤赠品不能删除
          { title: '', key: 'sourceId', width: '0', type: FormTypes.normal },
          // 888
          // {
          //   title: this.$t('setailManagement.warehouseName'), key: 'depotId', width: '7%', type: FormTypes.select, 
          //   placeholder: this.$t('inPrint.pleaseTnter') + '${title}', options: [],
          //   allowSearch: true,
          //   validateRules: [{ required: true, message: '${title}' + this.$t('inPrint.cannotTe') }]
          // },
        ]
      },
      confirmLoading: false,
      validatorRules: {
        operTime: {
          rules: [
            { required: true, message: this.$t('popup.pleaseEnterDocumentDate') + '!' }
          ]
        },
        organId: {
          rules: [
            { required: true, message: this.$t('popup.pleaseSupplier') + '!' }
          ]
        },
          number:{
            rules: [
              { required: true, message: this.$t('otherJS.DocumentNoFailure') }
            ]
          },
          linkNumber:{
            rules: [
              { required: true, message: this.$t('popup.pleaseSelectAssociated') }
            ]
          }
      },
      url: {
        add: '/depotHead/addDepotHeadAndDetail',
        edit: '/depotHead/updateDepotHeadAndDetail',
        detailList: '/depotItem/getDetailList'
      }
    }
  },
  created() {
  },
  methods: {
    //调用完edit()方法之后会自动调用此方法
    editAfter() {
      this.arrList = []
      this.billStatus = '0'
      this.rowCanEdit = true
      // this.materialTable.columns[1].type = FormTypes.popupJsh
      this.getSystemConfig()
      this.changeColumnHide()
      this.changeFormTypes(this.materialTable.columns, 'preNumber', 0)
      this.changeFormTypes(this.materialTable.columns, 'finishNumber', 0)
      if (this.action === 'add') {
        this.addInit(this.prefixNo)
        this.fileList = []
        this.$nextTick(() => {
          handleIntroJs(this.prefixNo, 1)
        })
      } else {
        if (this.model.linkNumber) {
          this.rowCanEdit = false
          this.materialTable.columns[5].type = FormTypes.normal
        }
        this.model.operTime = this.model.operTimeStr
        if (this.model.accountId == null) {
          this.model.accountId = 0
          this.manyAccountBtnStatus = true
          this.accountIdList = this.model.accountIdList
          this.accountMoneyList = this.model.accountMoneyList
        } else {
          this.manyAccountBtnStatus = false
        }
        
        console.log('编辑数据：',this.model);
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'organId', 'addressId',
          'deliveryMethod', 'arrivalTime', 'operTime', 'number', 'userName', 'creator', 'linkNumber', 'remark','custom5',
            'discount', 'discountMoney', 'discountLastMoney', 'accountId', 'changeAmount'))
        });
        // 加载子表数据
        let params = {
          headerId: this.model.id,
          mpList: getMpListShort(Vue.ls.get('materialPropertyList'))  //扩展属性
        }
        let url = this.readOnly ? this.url.detailList : this.url.detailList;
        this.requestSubTableData(url, params, this.materialTable);
        let arr = []
        this.materialTable.dataSource.forEach(item => {
          arr.push(item.materialId)
        });
        this.materialIds = arr.toString()
        this.changeMaterialIds()
      }
      //复制新增单据-初始化单号和日期
      if (this.action === 'copyAdd') {
        this.model.id = ''
        this.model.tenantId = ''
        this.copyAddInit(this.prefixNo)
      }
      this.initSupplier()
      // this.initAccount()
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let totalPrice = 0
      let billMain = Object.assign(this.model, allValues.formValue)
      let detailArr = allValues.tablesValue[0].values
      billMain.type = '其它'
      billMain.subType = '厂家报价'
      billMain.defaultNumber = billMain.number
      for (let item of detailArr) {
        item.depotId = '' //订单不需要仓库
        totalPrice += item.allPrice - 0
        item.custom5 = item.custom5 || this.form.getFieldValue('custom5')
      }
      billMain.totalPrice = 0 - totalPrice
      billMain.changeAmount = 0 - billMain.changeAmount
      if (billMain.accountId === 0) {
        billMain.accountId = ''
      }
      this.accountMoneyList = changeListFmtMinus(this.accountMoneyList)
      billMain.accountIdList = this.accountIdList.length > 0 ? JSON.stringify(this.accountIdList) : ""
      billMain.accountMoneyList = this.accountMoneyList.length > 0 ? JSON.stringify(this.accountMoneyList) : ""
      if (this.fileList && this.fileList.length > 0) {
        billMain.fileName = this.fileList
      } else {
        billMain.fileName = ''
      }
      if (this.model.id) {
        billMain.id = this.model.id
      }
      billMain.status = this.billStatus
      let fileList = JSON.stringify(JSON.parse(localStorage.getItem("fileList")))
      // console.log('billMain :>> ', billMain);
      // console.log('detailArr :>> ', detailArr);
      // return
      return {
        info: JSON.stringify(billMain),
        attachment: fileList,
        rows: JSON.stringify(detailArr),
      }
    },
    handleHistoryBillList() {
      let organId = this.form.getFieldValue('organId')
      this.$refs.historyBillListModalForm.show('其它', this.$t('manuManagement.purchaseOrder'), this.$t('manuManagement.supplier'), organId);
      this.$refs.historyBillListModalForm.disableSubmit = false;
    },
    onSearchLinkNumber() {
      let organId = this.form.getFieldValue('organId')
      // this.$refs.linkBillList.show('其它', this.$t('manuManagement.purchaseOrder'), this.$t('warehouseManagement.supplier'), "1,3", organId)
      this.$refs.linkBillList.show('其它', '采购订单', this.$t('warehouseManagement.supplier'), "1", organId, this.prefixNo)
      this.$refs.linkBillList.title = this.$t('popup.selectPurchaseOrder')
    },

    linkBillListOk(selectBillDetailRows, linkNumber, organId) {
      let selectBillRows = arguments[9]
      this.rowCanEdit = false
      this.materialTable.columns[5].type = FormTypes.normal
      this.changeFormTypes(this.materialTable.columns, 'preNumber', 1)
      this.changeFormTypes(this.materialTable.columns, 'finishNumber', 1)
      if(selectBillDetailRows && selectBillDetailRows.length>0) {
        let discountLastMoney = 0
        for(let j=0; j<selectBillDetailRows.length; j++) {
          let info = selectBillDetailRows[j];
          if (info.preNumber) {
            info.operNumber = info.preNumber - info.finishNumber
            info.unitPrice = info.purchaseDecimal
            info.allPrice = (info.operNumber * info.unitPrice).toFixed(2) - 0;
            info.taxLastMoney = info.allPrice
            discountLastMoney += info.allPrice
          }
          info.linkId = info.id
        }
        this.$nextTick(() => {
          this.form.setFieldsValue({
            'linkNumber': linkNumber,
            'custom5':selectBillRows[0] && (selectBillRows[0].custom5 || ''),
            'depotId':selectBillRows[0].depotId
          })
        })
        //给优惠后金额重新赋值
        if(discountLastMoney) {
          this.$nextTick(() => {
            this.form.setFieldsValue({
              'discountLastMoney': discountLastMoney.toFixed(2),
              'changeAmount': 0
            })
          });
        }
        this.materialTable.dataSource = selectBillDetailRows
        // 禁用修改赠品
        let giftArr = this.materialTable.dataSource.filter(v=>v.priceNote === '赠品' || v.sourceId)
        this.disabledRowIds = giftArr.map(v=>v.id)
        console.log('this.disabledRowIds :>> ', this.disabledRowIds);
      }
      this.$nextTick(() => {
          this.form.setFieldsValue({
            'organId': organId,
            'linkNumber': linkNumber,
          })
        })
    },
    getSystemConfig() {
      getCurrentSystemConfig().then((res) => {
        console.log(res);
        if (res.code === 200 && res.data) {
          this.purchaseBySaleFlag = res.data.purchaseBySaleFlag === '1' ? true : false
        }
      })
    },
    removeRows (text) {
      let item = this.materialTable.dataSource.find(v=>v.id === text.rowId)
      if(item && (item.priceNote === '赠品' || item.sourceId)){
        return;
      }
      this.$refs[this.refKeys[0]].removeRows(text.rowId)
    }
  }
}
</script>
<style scoped lang="less">
::v-deep .ant-spin-container .thead {
  background: #beddf9;
  & > .tr > .td {
    border-left: 1px solid #f2f2f2;
    text-align: center;
  }
}
</style>